/**
 * User: hoangnq
 * Date: 11/21/11
 * Time: 10:38 PM
 */
function insertThumbnail(thumbnail_id) {
    $('input[name="thumbnail_id"]').val(thumbnail_id);
    $("#thumbnail_preview").attr({
        "src": BASE_URI + 'libs/thumb/' + thumbnail_id,
        'class':'cboxElement'
    });
}
(function($) {
    $(function() {
        //tooltip
        $('#images-container img').hover(function() {
            $(this).attr('title', 'Click to insert image');
        });

        //cue up uniform
        $('select, #upload-box input[type=text], input[type=file], input[type=submit]').livequery(function() {
            $.uniform && $(this).uniform();
        });
        $('#files-nav li a').live('click', function(e) {

            e.preventDefault();

            var href_val = $(this).attr('href');

            //remove existing 'current' classes
            $('#files-nav li').removeClass('current');

            //add class to click anchor parent
            $(this).parent('li').addClass('current');

            //remove any notifications
            $('div.notification').fadeOut('fast');

            if ($(this).attr('title') != 'upload') {
                $('#files_right_pane').load(href_val + ' #files-wrapper', function() {
                    $(this).children().fadeIn('slow');
                });
            }
            else {
                var box = $('#upload-box');
                if (box.is(":visible")) {
                    // Hide - slide up.
                    box.fadeOut(800);
                }
                else {
                    // Show - slide down.
                    box.fadeIn(800);

                }
            }
        });

        $('#upload-box span.close').live('click', function() {

            $('#upload-box').fadeOut(800, function() {
                $(this).find('input[type=text], input[type=file]').val('');
                $.uniform.update('input[type=file]');
            });

        });

        $('select[name=parent_id]').live('change', function() {
            var folder_id = $(this).val();
            var controller = $(this).attr('title');
            var href_val = SITE_URL + 'admin/wysiwyg/' + controller + '/index/' + folder_id;
            $('#files_right_pane').load(href_val + ' #files-wrapper', function() {
                $(this).children().fadeIn('slow');
                var class_exists = $('#folder-id-' + folder_id).html();
                $('div.notification').fadeOut('fast');
                if (class_exists !== null) {
                    $('#files-nav li').removeClass('current');
                    $('li#folder-id-' + folder_id).addClass('current');
                }

            });
        })

        $('#files_right_pane').livequery(function() {
            $(this).children().fadeIn('slow');
            $('#upload-box').hide();
        });

//		$( 'td.image button, a.button').livequery(function() {
//			$(this).button();
//		});

    });
})(jQuery);
